perm filename PART13.TEX[TEX,RWF] blob
sn#545538 filedate 1980-10-22 generic text, type C, neo UTF8
COMMENT ⊗ VALID 00003 PAGES
C REC PAGE DESCRIPTION
C00001 00001
C00002 00002 \example
C00006 00003 The program generates values for {\tt A, B, C, D} in the order:
C00008 ENDMK
C⊗;
\example
Write a PASCAL program to find four positive integers $A < B < C < D$ for
which $B↑3 + C↑3 = A↑3 + D↑3$. In other words, find a positive integer that
can be represented two ways as the sum of two cubes. The program below finds
such an integer (one exists), but does not necessarily find the smallest one.
\startcode
PROGRAM SUMOFCUBES ( OUTPUT ) ;
(* THIS PROGRAM FINDS FOUR INTEGERS: 0 < A < B < C < D
FOR WHICH A*A*A + D*D*D = B*B*B + C*C*C *)
VAR A, B, C, D : INTEGER ;
BEGIN
A := 1 ;
B := 2 ;
C := 3 ;
D := 4 ;
WHILE A*A*A + D*D*D <> B*B*B +C*C*C DO
IF A < B - 1 THEN A := A + 1
ELSE
BEGIN
A := 1 ;
IF B < C - 1 THEN B := B + 1
ELSE
BEGIN
B := 2 ;
IF C < D + 1 THEN C := C + 1
ELSE
BEGIN
C := 3 ;
D := D + 1
END
END
END ;
WRITELN ( A, D, B, C )
END.
\endcode
\vfill\eject
The program generates values for {\tt A, B, C, D} in the order:
\dtable{\hfill#\hfill\qquad⊗\hfill#\hfill\qquad⊗\hfill#\hfill\qquad⊗\hfill#\hfill\cr
{\tt A}⊗{\tt B}⊗{\tt C}⊗{\tt D}\cr
1⊗2⊗3⊗4\cr
1⊗2⊗3⊗5\cr
1⊗2⊗4⊗5\cr
1⊗3⊗4⊗5\cr
2⊗3⊗4⊗5\cr
1⊗2⊗3⊗6\cr
1⊗2⊗4⊗6\cr
1⊗3⊗4⊗6\cr
2⊗3⊗4⊗6\cr
1⊗2⊗5⊗6\cr
1⊗3⊗5⊗6\cr
2⊗3⊗5⊗6\cr
1⊗4⊗5⊗6\cr
2⊗4⊗5⊗6\cr
3⊗4⊗5⊗6\cr
1⊗2⊗3⊗7\cr
⊗etc.⊗⊗\cr
}%end dtable
The program, upon finding $A↑3 + D↑3 ≠ B↑3 + C↑3$, increases the first of
$A$, $B$, $C$, $D$ that can be increased without becoming equal to the next
variable; it sets all the earlier variables back to their initial values.